import Sequelize from 'sequelize';

module.exports = app => {
	const DataTypes = app.Sequelize;

	const Model = app.model.define('ad', {
		id: {
			type: DataTypes.INTEGER(11),
			allowNull: false,
			primaryKey: true,
			autoIncrement: true
		},
		ad_position_id: {
			type: DataTypes.INTEGER(11),
			allowNull: true,
			defaultValue: 1  // 默认小程序轮播位，TODO：后期可以增加位置
		},
		media_type: {
			type: DataTypes.STRING(20),
			allowNull: true
		},
		name: {
			type: DataTypes.STRING(200),
			allowNull: true
		},
		link: {
			type: DataTypes.STRING(100),
			allowNull: true
		},
		image_url: {
			type: DataTypes.STRING(200),
			allowNull: true
		},
		content: {
			type: DataTypes.STRING(255),
			allowNull: true
		},
		end_time: {
			type: DataTypes.DATE,
			allowNull: true
		},
		enabled: {
			type: DataTypes.INTEGER(11),
			allowNull: true,
			defaultValue: 1
		},
		ad_position_idCopy: {
			type: DataTypes.INTEGER(6),
			allowNull: true,
			defaultValue: '0'
		},
		createdAt: {
			type: DataTypes.DATE,
			allowNull: false,
			defaultValue: Sequelize.NOW
		},
		updatedAt: {
			type: DataTypes.DATE,
			allowNull: false,
			defaultValue: Sequelize.NOW
		},
		sort: {
			type: DataTypes.INTEGER(11),
			allowNull: true
		},
		is_delete: {
			type: DataTypes.INTEGER(1).UNSIGNED,
			allowNull: false,
			defaultValue: '0',
			comment: '是否删除，0->存在，1->删除'
		},
        shop_id: {
            type: DataTypes.INTEGER(11),
            allowNull: true,
            defaultValue: null,
            comment: '商家ID，预留SASS功能'
        },
	}, {
		tableName: 'ad',
		timestamps: false
	});
	
	Model.sync({ alter: true });
	Model.associate = function() {

	}

	return Model;
};
